home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form BounceForm
- AutoRedraw = -1 'True
- BackColor = &H00000000&
- ClientHeight = 4095
- ClientLeft = 2385
- ClientTop = 1605
- ClientWidth = 4335
- ControlBox = 0 'False
- Height = 4500
- Icon = "BOUNCER.frx":0000
- Left = 2325
- LinkTopic = "Form1"
- MaxButton = 0 'False
- MinButton = 0 'False
- MousePointer = 99 'Custom
- ScaleHeight = 273
- ScaleMode = 3 'Pixel
- ScaleWidth = 289
- Top = 1260
- Width = 4455
- WindowState = 2 'Maximized
- Attribute VB_Name = "BounceForm"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- Dim xmax As Integer
- Dim ymax As Integer
- Dim NumBalls As Integer
- Dim BallR() As Integer
- Dim BallX() As Integer
- Dim BallY() As Integer
- Dim BallDx() As Integer
- Dim BallDy() As Integer
- Dim BallClr() As Long
- Dim Playing As Boolean
- ' ************************************************
- ' Generate some random data.
- ' ************************************************
- Sub InitData()
- Dim ball As Integer
- Dim R As Integer
- ' See how many balls there should be.
- NumBalls = 20
- ReDim BallR(1 To NumBalls)
- ReDim BallX(1 To NumBalls)
- ReDim BallY(1 To NumBalls)
- ReDim BallDx(1 To NumBalls)
- ReDim BallDy(1 To NumBalls)
- ReDim BallClr(1 To NumBalls)
- ' Set the initial ball data.
- For ball = 1 To NumBalls
- R = Int(20 * Rnd + 15)
- BallR(ball) = R
- BallX(ball) = Int((xmax - R + 1) * Rnd)
- BallY(ball) = Int((ymax - R + 1) * Rnd)
- BallClr(ball) = QBColor(Int(15 * Rnd) + 1)
- ' Make sure it's moving at least a little.
- Do
- BallDx(ball) = Int(21 * Rnd - 10)
- BallDy(ball) = Int(21 * Rnd - 10)
- Loop While BallDx(ball) = 0 And BallDy(ball) = 0
- Next ball
- End Sub
- ' ************************************************
- ' Play the animation.
- ' ************************************************
- Sub PlayData()
- Dim mpf As Long ' Milliseconds per frame.
- Dim ball As Integer
- Dim next_time As Long
- ' Set FillStyle to vbSolid.
- FillStyle = vbSolid
- ' Display 30 frames per second.
- mpf = 1000 \ 30
- ' Start the animation.
- next_time = GetTickCount()
- Do
- ' Draw the balls.
- Cls
- For ball = 1 To NumBalls
- FillColor = BallClr(ball)
- Circle (BallX(ball), BallY(ball)), _
- BallR(ball), BallClr(ball)
- Next ball
-
- ' Move the balls.
- For ball = 1 To NumBalls
- BallX(ball) = BallX(ball) + BallDx(ball)
- If BallX(ball) < BallR(ball) Then
- BallX(ball) = 2 * BallR(ball) - BallX(ball)
- BallDx(ball) = -BallDx(ball)
- ElseIf BallX(ball) > xmax - BallR(ball) Then
- BallX(ball) = 2 * (xmax - BallR(ball)) - BallX(ball)
- BallDx(ball) = -BallDx(ball)
- End If
-
- BallY(ball) = BallY(ball) + BallDy(ball)
- If BallY(ball) < BallR(ball) Then
- BallY(ball) = 2 * BallR(ball) - BallY(ball)
- BallDy(ball) = -BallDy(ball)
- ElseIf BallY(ball) > ymax - BallR(ball) Then
- BallY(ball) = 2 * (ymax - BallR(ball)) - BallY(ball)
- BallDy(ball) = -BallDy(ball)
- End If
- Next ball
-
- ' Wait until it's time for the next frame.
- next_time = next_time + mpf
- WaitTill next_time
- Loop
- End Sub
- Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
- End
- End Sub
- Private Sub Form_Load()
- Me.Show
- InitData
- PlayData
- End Sub
- Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
- End
- End Sub
- Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
- Static times_done As Integer
- times_done = times_done + 1
- ' If this is one of the first couple times,
- ' ignore the event.
- If times_done <= 2 Then Exit Sub
- ' If the mouse has not actually moved,
- ' ignore the event.
- If X = Screen.Width And Y = Screen.Height Then Exit Sub
- ' Stop.
- End
- End Sub
- Private Sub Form_Resize()
- xmax = ScaleWidth - 1
- ymax = ScaleHeight - 1
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- End
- End Sub
-